package com.example.jackson.util;

import com.example.jackson.dto.ProductDTO;
import com.example.jackson.dto.Result;

import java.math.BigDecimal;
import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class ResultAssert {
    void assertResult(Result<List<ProductDTO>> result) {
        assertNotNull(result);
        assertThat(result.getCode()).isEqualTo(200);
        List<ProductDTO> productDTOS = result.getData();
        assertNotNull(productDTOS);
        assertEquals(2, productDTOS.size());
        ProductDTO product = productDTOS.get(0);
        assertThat(product.getCode()).isEqualTo("1001");
        assertThat(product.getName()).isEqualTo("手机保护壳");
        assertThat(product.getPrice()).isEqualTo(new BigDecimal("15"));
        assertThat(product.isNewArrival()).isTrue();

        ProductDTO product2 = productDTOS.get(1);
        assertThat(product2.getCode()).isEqualTo("1002");
        assertThat(product2.getName()).isEqualTo("手机贴膜");
        assertThat(product2.getPrice()).isEqualTo(new BigDecimal("9.43"));
        assertThat(product2.isNewArrival()).isTrue();
    }
}
